package com.ch.android.networklib

import com.ch.android.networklib.data.BaseResultData
import com.ch.android.networklib.data.CloseLiveData
import com.ch.android.networklib.data.LiveListItemData
import com.ch.android.networklib.data.LiveTypeData
import com.ch.android.networklib.data.MyLoginData
import com.ch.android.networklib.data.OpenLiveData
import com.ch.android.networklib.data.UserLoginData
import com.ch.android.networklib.data.UserLoginReq
import com.ch.android.networklib.data.WatchLiveData
import io.reactivex.rxjava3.core.Observable
import okhttp3.MultipartBody
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Part
import retrofit2.http.Query


/**
 * Author: conghao
 * Date: 2023/12/26 10:05
 * Description: ApiService
 */


interface ApiService {
    companion object {
//        const val BASE_URL = "http://10.59.9.18/"
        const val BASE_URL = "http://wq.bwstudent.com:7999/"

        const val REGISTER_PATH = "/live-user/v1/register"
        const val USER_LOGIN_PATH = "/live-user/v1/login"
        const val WX_LOGIN_PATH = "/live-user/wxLogin"
    }

    /**
     * 用户注册 使用RxJava
     */
    @POST(USER_LOGIN_PATH)
    fun userLoginA(@Body req: UserLoginReq): Observable<BaseResultData<MyLoginData?>>

    /**
     * 直播登录 使用协程
     */
    @POST(USER_LOGIN_PATH)
    suspend fun userLogin(@Body request: UserLoginReq): BaseResultData<UserLoginData?>

    /**
     * 查询直播类型
     */
    @GET("/live-platform/findLiveTypeList")
    suspend fun getLiveTypeList(): BaseResultData<MutableList<LiveTypeData>>

    /**
     * 查询直播列表
     */
    @GET("/live-platform/findLiveList")
    suspend fun getLiveList(
        @Query("liveType") liveType: Int,
        @Query("page") page: Int,
        @Query("size") size: Int
    ): BaseResultData<List<LiveListItemData>>

    /**
     * 申请开启直播
     */
    @Multipart
    @POST("/live-platform/verify/openLive")
    suspend fun openLive(
        @Header("sessionId") sessionId: String,
        @Query("liveType") liveType: Int,
        @Query("liveTitle") liveTitle: String,
        @Query("longitude") longitude: Double = 116.305513,
        @Query("latitude") latitude: Double = 40.045718,
        @Part part: MultipartBody.Part
    ): BaseResultData<OpenLiveData?>

    /**
     * 关闭直播
     */
    @DELETE("/live-platform/verify/closeLive")
    suspend fun closeLive(@Header("sessionId") sessionId: String): BaseResultData<CloseLiveData>

    /**
     * 通知BW服务器 开始推流
     */
    @PUT("/live-platform/verify/startPushStream")
    suspend fun startPushStream(
        @Header("sessionId") sessionId: String,
        @Query("liveId") liveId: Int
    ): BaseResultData<Unit>

    /**
     * 观看直播
     */
    @GET("/live-platform/watchLive")
    suspend fun watchLive(
        @Header("sessionId") sessionId: String,
        @Query("liveId") liveId: Int
    ): BaseResultData<WatchLiveData>
}